package com.doucat.support.component.fragment.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;

import com.doucat.support.component.fragment.base.BaseFragment;
import com.doucat.support.constant.PublicBundleConstant;
import com.tonly.doucatlibrary.R;

/**
 * -----------------------------------------------------------------
 * Copyright (C) 2021-2031, by tonly, All rights reserved.
 * -----------------------------------------------------------------
 * File: TitleActivity.java
 * Author: wangfy
 * Create: 2021/5/25 16:30
 */
public class ToolbarFragment extends BaseFragment {
    protected Toolbar toolbar;
    private TextView tvTitle;
    private FrameLayout frameTitleContent;

    @Override
    public void onRootViewCreate(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        setBaseFragmentContentView(R.layout.fragment_title);
        toolbar = findViewById(R.id.toolbar);
        tvTitle = findViewById(R.id.tvTitle);
        frameTitleContent = findViewById(R.id.frame_fragment_TitleContent);
//        设置后影响menu，左边的图标不显示
//        setSupportActionBar(toolbar);
//        getSupportActionBar().setTitle("");
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
        Bundle bundle=getArguments();
        if(bundle==null){
            toolbar.setVisibility(View.GONE);
        }else {
            String title=bundle.getString(PublicBundleConstant.URL_TITLE);
            setTitle(title);
        }
    }

    public View getContent(){
        return frameTitleContent;
    }

    public void setTitleFrameLayout(int layoutResID) {
        frameTitleContent.removeAllViews();
        View.inflate(getContext(), layoutResID, frameTitleContent);
    }

    public void setTitle(String title){
        tvTitle.setText(title);
    }

    public void hideBackButton(){
        toolbar.setNavigationIcon(null);
    }

}